package cn.hx.controller.front.item;

import cn.hx.entity.Item;
import cn.hx.entity.UserReport;
import cn.hx.service.UserReportService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class ItemRevealFullController {
    @Resource
    private UserReportService userReportService;

    @GetMapping("item/revealFull")
    public String getRevealFull() {
        return "re_approve/revealFull";
    }

    @GetMapping("re_approve/reveal_full")
    @ResponseBody
    public Map<String, Object> queryList(@RequestParam(defaultValue = "1") Integer pageId, String regionApproveName, Integer itemState) {
        Map<String, Object> map = new HashMap<>();
        if (regionApproveName != null && regionApproveName != "" || itemState != null) {
            UserReport userReport = new UserReport();
            Item item = new Item();
            item.setName(regionApproveName);

            userReport.setStatus(itemState);
            userReport.setItem(item);
            List<UserReport> userReports = userReportService.queryAllCheck(userReport);
            System.out.println(userReports);
            map.put("list", userReports);
        } else {
            List<UserReport> userReports = userReportService.queryByLimitStatus((pageId - 1) * 7, 7);
            map.put("list", userReports);

        }
        UserReport userReport = new UserReport();
        userReport.setStatus(itemState);
        int count = userReportService.count(userReport);
        int totalPage = 0;
        if (count % 7 == 0) {
            totalPage = count / 5;
        } else {
            totalPage = count / 7 + 1;
        }
        int total = count;
        map.put("totalPage", totalPage);
        return map;
    }
}